package com.cloudsigns.factorymanager2.produce.utils;

import android.text.TextUtils;

import com.cloudsigns.factorymanager2.cusenum.CommonEnum;

import org.json.JSONException;
import org.json.JSONObject;

public class ParseJson {

    /**
     * 订单状态
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.ProduceOrderStatus parseProdutOrderStatus(JSONObject jsonObj,String key) throws JSONException {
        String status = jsonObj.getString(key);
        if (null != status) {
            if (status.equals("CREATED")) {
                return CommonEnum.ProduceOrderStatus.CREATED;
            } else if (status.equals("EDIT")) {
                return CommonEnum.ProduceOrderStatus.EDIT;
            }else if (status.equals("EDITED")) {
                return CommonEnum.ProduceOrderStatus.EDITED;
            } else if (status.equals("SEND")) {
                return CommonEnum.ProduceOrderStatus.SEND;
            } else if (status.equals("RECEIVED")) {
                return CommonEnum.ProduceOrderStatus.RECEIVED;
            } else if (status.equals("RETURNED")) {
                return CommonEnum.ProduceOrderStatus.RETURNED;
            } else if (status.equals("COMPLETED")) {
                return CommonEnum.ProduceOrderStatus.COMPLETED;
            }
        }
        return null;
    }

    /**
     * 订单级别
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.ProduceOrderLevel parseProdutOrderLevel(JSONObject jsonObj,String key) throws JSONException {
        String level = jsonObj.getString(key);
        if (!TextUtils.isEmpty(level)) {
            if (level.equals("VERY_IMPORTANT")) {
                return CommonEnum.ProduceOrderLevel.VERY_IMPORTANT;
            }else if (level.equals("MORE_IMPORTANT")){
                return CommonEnum.ProduceOrderLevel.MORE_IMPORTANT;
            }else if (level.equals("GENERALLY_IMPORTANT")){
                return CommonEnum.ProduceOrderLevel.GENERALLY_IMPORTANT;
            }else if(level.equals("NORMAL")){
                return CommonEnum.ProduceOrderLevel.NORMAL;
            }
        }
        return null;
    }

    /**
     * 反馈类型
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.WorkPartType parseFeedbackType(JSONObject jsonObj,String key) throws JSONException {
        String type=jsonObj.getString(key);
        if (!TextUtils.isEmpty(type)) {
            if (type.equals("NORMAL")) {
                return CommonEnum.WorkPartType.NORMAL;
            }else if (type.equals("UNUSUAL")){
                return CommonEnum.WorkPartType.UNUSUAL;
            }else if(type.equals("APPLY_ADJUST")){
                return CommonEnum.WorkPartType.APPLY_ADJUST;
            }else if(type.equals("APPLY_RETURN")){
                return CommonEnum.WorkPartType.APPLY_RETURN;
            }else if(type.equals("APPLY_SCRAP")){
                return CommonEnum.WorkPartType.APPLY_SCRAP;
            }
        }
        return null;
    }

    /**
     * 异常反馈子类型
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.WorkPartSubType parseSubType(JSONObject jsonObj,String key) throws JSONException {
        String subType = jsonObj.getString("subType");
        if (!TextUtils.isEmpty(subType)) {
            if (subType.equals("PLAN_UNUSUAL")) {
                return CommonEnum.WorkPartSubType.PLAN_UNUSUAL;
            }else if(subType.equals("PRODUCE_UNUSUAL")){
                return CommonEnum.WorkPartSubType.PRODUCE_UNUSUAL;
            }
        }
        return null;
    }

    /**
     * 日计划日期类型
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.ScheduleDateType parseScheduleDateType(JSONObject jsonObj,String key) throws JSONException {
        String scheduleDateType = jsonObj.getString("scheduleDateType");
        if (!TextUtils.isEmpty(scheduleDateType)) {
            if (scheduleDateType.equals("NORMAL")) {
                return CommonEnum.ScheduleDateType.NORMAL;
            }else if(scheduleDateType.equals("ADJUST")){
                return CommonEnum.ScheduleDateType.ADJUST;
            }else if(scheduleDateType.equals("RETURN")){
                return CommonEnum.ScheduleDateType.RETURN;
            }
        }
        return null;
    }

    /**
     * 产品规格
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.ProductShapeType parseProductShapeType(JSONObject jsonObj,String key) throws JSONException {
        String shapeType = jsonObj.getString("type");
        if (shapeType.equals("ROUND")) {
            return CommonEnum.ProductShapeType.ROUND;
        }else if (shapeType.equals("RECTANGLE")){
            return CommonEnum.ProductShapeType.RECTANGLE;
        }else if (shapeType.equals("SPECIALSHAPE")){
            return CommonEnum.ProductShapeType.SPECIALSHAPE;
        }
        return null;
    }

    /**
     * 生产班组 异常反馈状态
     * @param jsonObj
     * @param key
     * @return
     * @throws JSONException
     */
    public static CommonEnum.FeedbackStatus parseFeedbackStatus(JSONObject jsonObj,String key) throws JSONException {
        String feedbackStatus = jsonObj.getString(key);
        if (null != feedbackStatus) {
            if (feedbackStatus.equals("WAIT_CONFIRM")) {
                return CommonEnum.FeedbackStatus.WAIT_CONFIRM;
            } else if (feedbackStatus.equals("CONFIRM_FINISH")) {
                return CommonEnum.FeedbackStatus.CONFIRM_FINISH;
            }else if (feedbackStatus.equals("WAIT_REPLY_CONFIRM")) {
                return CommonEnum.FeedbackStatus.WAIT_REPLY_CONFIRM;
            }else if (feedbackStatus.equals("REPLY_CONFIRM_FINISH")) {
                return CommonEnum.FeedbackStatus.REPLY_CONFIRM_FINISH;
            }
        }
        return null;
    }


}
